<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8" http-equiv="content-type" content="text/html">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>我的发布</title>

<link href="css/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="css/mylike.css" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" type="text/css" href="css/mypublish.css"/>
<link rel="stylesheet" type="text/css" href="css/need/layer.css"/>
<script type="text/javascript" src="js/layer.js"></script>

<script type="text/javascript" src="js/tab.js"></script>
<style>
.selledDialog{
	position: fixed;
	bottom: -200px;
	width: 100%;
	background-color: white;
}
</style>
<script>
$(document).bind('mobileinit',function(){
 $.mobile.changePage.defaults.changeHash = false;
 $.mobile.hashListeningEnabled = false;
 $.mobile.pushStateEnabled = false;
});
</script>
<script src="js/jquery.mobile-1.4.5.min.js" type="text/javascript"></script>
</head>
<body>
<div data-role="page">
 	<div data-role="content" id="content">
 		<div style="display:none;position:fixed;width:100%;height:100%;left:0;top:0;background-color:rgba(0,0,0,.7);" id="shade" onclick="closeSelledDialog()">
 		
 		</div>
		<div id="tab">
			<h2>
				<span class="on stab" to="0">闲置</span>
				<span class="stab" to="1">专题</span>
			</h2>
			
			<ul  style="display:block;" class="ulContent">
			</ul>
				
		</div>
		<div class="selledDialog">
			<div>
			请在下面的用户中，选出购买用户：
			</div>
			<div >
				<select id="bugUserSelelct">
				</select>
			</div>
			<div >
				<input type="button" value="确认购买" style="width:100%" onclick="haveSell(this)" id="checkBug" style="	"/>
				<input type="button" value="取消" style="width: 100%" onclick="closeSelledDialog()" />
			</div>
		</div>
 	</div>
 	</div>
</div>
</body>
<script type="text/javascript">
var isLast = false;
$(function(){
	setBase();
	//stab点击事件
	$(".stab").click(function(){
		isLast = false;
		$(".stab").removeClass("on");
		$(this).addClass("on");
		switch(parseInt($(this).attr("to"))){
		case 0:
			$(".ulContent").html("");
			getMyPublishThingList(1);
			break;
		case 1:
			$(".ulContent").html("");
			getMyPublishThingStoryList(1);
			break;
		}
	});
})
function setBase(){
	getMyPublishThingList(1);
}
//收缩选择可能购买人的框
function closeSelledDialog(){
	$("#shade").css("display","none");
	$(".selledDialog").animate({bottom:'-200px'});
}
//弹出选择可能购买人的框
function showSelledDialog(input){
	
	$.post("api/myself/getMaybeBugUser.do",{id:$(input).attr("thingId")},function(data){
		if(data["STATUS"]=="OK"){
			$("#checkBug").attr("thingId",$(input).attr("thingId"));
			$("#checkBug").attr("userId",$(input).attr("userId"));
			var resultListJson = eval("("+data["RESULTLIST"]+")");
			var html= '';
			
			html+='<option value="" selected>请从聊天记录中选取购买人</option>';
			$.each(resultListJson,function(keyDaily,valueDaily){
				html+='<option value="'+valueDaily.USERID+'">'+valueDaily.NICKNAME+'</option>';
			});
			$("#bugUserSelelct").html(html);
			$("#shade").css("display","block");
			$(".selledDialog").animate({bottom:'0px'});
		}else{
			 //信息框
			  layer.open({
			    content: data.DESC
			    ,btn: '我知道了'
			  });
		}
	},'json');
		
		
	}
//加载本人的闲置列表
function getMyPublishThingList(pageNum){
	if(isLast == false){
		$(".mylike-c").remove();
		var url = "api/myself/getMyPublishThingList.do";
		$.post(url,{pageNum:pageNum,pageSize:10},
		function(data){
			if(data["STATUS"]=="OK"){
				var resultListJson = eval("("+data["RESULTLIST"]+")");
				var html= '';
				$.each(resultListJson,function(keyDaily,valueDaily){
					html+='<div class="mylike-c">';
					html+='<div class="text">';
					html+='<p>'+valueDaily.TITLE+'</p>';
					html+='</div>';
					html+='<div class="goods-price">';
					html+='<span>'+valueDaily.COST+'</span>';
					html+='<span class="o-price">'+valueDaily.ORIGINCOST+'</span>';
					html+='</div>';
					if(valueDaily.IMGS!=''){
						html+='<div class="pic">';
						var img = valueDaily.IMGS.split(',');
						for(var ii=0;ii<img.length;ii++){
							html+='<img src="'+img[ii]+'"/>';
						}
						html+='</div>';
					}
					html+='<div class="bottom">';
					html+='<a class="assess" href="javascript:void(0)">'+valueDaily.COMMENTNUM+'</a>';
					html+='<a class="like" href="javascript:void(0)">'+valueDaily.LIKE+'</a>';
					html+='<span>'+valueDaily.TIME+'<img src="images/time1.png"/></span>';
					html+='</div>';

					html+='<div class="op-btn">';
					html+='<input type="button" value="删除" data-role="none" thingId="'+valueDaily.THINGID+'" onclick="thingCancel(this)"/>';
					//html+='<input type="button" value="修改" data-role="none" thingId="'+valueDaily.THINGID+'" />';
					html+='<input type="button" value="已售出" data-role="none" thingId="'+valueDaily.THINGID+'" onclick="showSelledDialog(this)"/>';
					html+='</div>';
					html+='</div>';
				});
				isLast = data["isLast"];
				$(".ulContent").append(html);
			}
		},'json');
	}
}
//取消发布
function thingCancel(input){
	layer.open({
	      content: '确认删除吗？不可恢复喔'
	      ,btn: ['狠心删除', '不了']
	      ,yes: function(index){
	    	  var id = $(input).attr("thingId");
	    		$.post("api/myself/thingCancel.do",{id:id},function(data){
	    			if(data["STATUS"]=="OK"){
	    				$(input).attr("disabled","disabled");
	    				$(input).val("已删除");
	    			}
	    		},'json');
	      }
	    });
	
}
//已出售
function haveSell(input){
	var id = $(input).attr("thingId");
	var userId = $("#bugUserSelelct").val();
	$.post("api/myself/haveSell.do",{id:id,bugUserId:userId},function(data){
		if(data["STATUS"]=="OK"){
			$(input).attr("disabled","disabled");
		}
	},'json');
}
//加载本人故事列表
function getMyPublishThingStoryList(pageNum){
	if(isLast == false){
		$(".mylike-c").remove();
		var url = "api/myself/getMyPublishThingStoryList.do";
		$.post(url,{pageNum:pageNum,pageSize:10},
		function(data){
			if(data["STATUS"]=="OK"){
				var resultListJson = eval("("+data["RESULTLIST"]+")");
				var html= '';
				$.each(resultListJson,function(keyDaily,valueDaily){
					html+='<div class="mylike-c">';
					html+='<div class="text">';
					html+='<div class="text-left">'+valueDaily.TOPIC+'</div>';
					html+='<p>'+valueDaily.TITLE+'</p>';
					html+='</div>';
					if(valueDaily.IMGS!=''){
						html+='<div class="pic">';
						var img = valueDaily.IMGS.split(',');
						for(var ii=0;ii<img.length;ii++){
							html+='<img src="'+img[ii]+'"/>';
						}
						html+='</div>';
					}
					html+='<div class="bottom">';
					html+='<a class="assess" href="javascript:void(0)">'+valueDaily.COMMENTNUM+'</a>';
					html+='<a class="like" href="javascript:void(0)">'+valueDaily.LIKE+'</a>';
					html+='</div>';

					html+='<div class="op-btn">';
					html+='<input type="button" value="删除" data-role="none" id="'+valueDaily.THINGSTORYID+'"/>';
					//html+='<input type="button" value="修改" data-role="none" id="'+valueDaily.THINGSTORYID+'"/>';
					html+='</div>';
					html+='</div>';
				});
				isLast = data["isLast"];
				$(".ulContent").append(html);
			}
		},'json');
	}
}
</script>
</html>